const express = require("express");
const app = express();
const path = require("path");


// 创建服务
// http
let portFn=(port ,H)=>{
  console.log(`${H},正在监听${port }端口`)
  return port 
}
const http = require("http");
let httpServer = http.createServer(app);
httpServer.listen(portFn(8050,'http'));

// https
let fs = require('fs');
let credentials = {
	key: fs.readFileSync(path.join(__dirname, 'sslcert/ssl.key')),
  cert: fs.readFileSync(path.join(__dirname, 'sslcert/ssl.crt'))
};
let https = require('https');
let httpsServer = https.createServer(credentials, app);
httpsServer.listen(portFn(8060,'https'));

// Socket
// 侦听Socket 端口
const io = require("socket.io")(httpsServer);
const socket = require("./socket");
socket(io);


// 路由
let router = express.Router()


// debug
// var morgan = require('morgan');
// app.use(morgan('dev'));

// 托管静态资源到www/dist目录下
let history = require('connect-history-api-fallback');
let historyOption = require("./pub/history");
app.use(history(historyOption));
app.use(express.static(path.join(__dirname, "www")));





